package com.globallogic.addtoken;

import java.util.List;

import com.globallogic.draw.Circle;
import com.globallogic.draw.DrawContainer;
import com.globallogic.inout.Out;
import com.globallogic.token.TokenHandler;
import com.globallogic.token.TokenProcessor;

public class TokenHandlerCircle implements TokenHandler {

	@Override
	public void execute(TokenProcessor tokenProcessor, List<String> params) {
		
		if (parceParams(params)) {

			DrawContainer.getInstance().addDrawObject(new Circle(radius));
			Out.printLn("Circle with radius " + radius + " has been added.");
		    
		}
			
	}
	
	private boolean parceParams(List<String> params) {
		
		if (params.size() == 0) {
            
			Out.printLn("Radius has not been specified for creating Circle");

			return false;
            
		} 			
		
		try {
			
		    radius = Integer.parseInt(params.get(0));
		    
		    if (radius < 0) {

		    	Out.printLn("Radius should be a positive integer value");
		    	
				return false;
		    	
		    }
			
		    return true;
		    
		} catch (NumberFormatException e) {

			Out.printLn("Radius should be an integer value");
			
		}
			
		return false;
		
	}
	
	private int radius;
	
}
